﻿using Framework;
using UnityEngine;
using UnityEngine.Events;

namespace Project
{
    public class PlayerBuffSystem : ISingeleton
    {
        public static PlayerBuffSystem Global => Singleton<PlayerBuffSystem>.Instance;

        private IBuffOwner player;
        private BuffMgrPanel panel;

        void ISingeleton.Init()
        {

        }
        public void RegisterAddIconEvent(UnityAction<GameObject> callback)
        {
            EventCenter.GetInstance().AddEventListener(player.AddIconEventName, callback);
        }
        public void UnRegisterAddIconEvent(UnityAction<GameObject> callback)
        {
            EventCenter.GetInstance().AddEventListener(player.AddIconEventName, callback);
        }
        public void RegisterPlayer(IBuffOwner owner)
        {
            player = owner;
            if (panel == null)
            {
                UIManager.GetInstance()
                    .ShowPanel<BuffMgrPanel>("BuffMgrPanel", E_UI_Layer.Top, panel => this.panel = panel);
            }
        }
        public void AddBuff(BuffID buffID)
        {
            BuffSystem.Global.AddBuff(player, buffID);
        }
        public void RemoveBuff(BuffID buffID)
        {
            BuffSystem.Global.RemoveBuff(player, buffID);
        }
        public double CalcAllPassiveBuff(double value)
        {
            return BuffSystem.Global.CalcAllPassiveBuff(player, value);
        }
        public bool Contains(BuffID buffID)
        {
            return BuffSystem.Global.Contains(player, buffID);
        }
        public void Clear()
        {
            BuffSystem.Global.Clear(player);
        }
    }
}